package java_class_work.week04.rectDemo;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

/**
 * @Author Tiam
 * @Date 2022/10/3 22:18
 * @Description:
 */
public class Example6_9 {
    public static void main(String[] args) {
        try {
            Class<?> cs = Class.forName("java_class_work.week04.rectDemo.Rect");
            //cs = Rect.class;
            // 返回一个无参构造方法
            Constructor<?> constructor = cs.getDeclaredConstructor();
            // 实例化对象
            Rect rect = (Rect) constructor.newInstance();
            double area = rect.getArea();
            System.out.println(area);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
    }
}
